import Mock from "mockjs";
import moduledata from './data.js'

Mock.setup({
    timeout: '200-2000',//单位为毫秒
})
 
function DoMock() {
    let env = process.env.NODE_ENV;
    console.log(env)
    if (env == 'development') {
        console.log(`执行数据模拟...`);
        moduledata.forEach((item) => {
            item.url = new RegExp(item.url)
            item.response = typeof (item.response) == 'function' ? item.response() : item.response;
            Mock.mock(item.url, item.method, (req) => {
                return Mock.mock(item.response);
            })
        })
    }
}


export default { DoMock }
